package com.mali.malibackendproduct.listens;


import com.mali.backendcommon.rpc.ProductService;
import com.mali.malibackendmodel.pojo.Product;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;



@Component
@RequiredArgsConstructor
@Slf4j
public class downLineListen {
    @Autowired
    private ProductService productService;

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "dlq.queue", durable = "true"),
            exchange = @Exchange(name = "dlx.exchange", type = ExchangeTypes.DIRECT),
            key = {"dlq.key"}
    ))
    public void downLine(Product product) throws Exception {

        try {
            productService.downLine(product);
        } catch (Exception e) {
            throw new Exception("消息队列启动失败");
        }

    }
}
